<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/29/0029
 * Time: 9:56
 */

namespace app\sports_admin\controller;
use app\exception\RuleException;
use app\sports_admin\model\Rule as RuleModel;
use think\Request;

//权限管理控制器
class Rule extends Base
{
    protected $beforeActionList = [
        'isAdmin'  =>  ['only'=>'index,update'],
        'operationSelect'=>['only'=>'index'],
        'operationUpdate'=>['only'=>'update']
    ];
    //权限列表
    public function index()
    {
        //获取权限
        $ruleList = RuleModel::ruleList();
        return view('index',compact('ruleList'));
    }
    /**
     * 修改权限
     */
    public function update(Request $request)
    {
        if($request->isAjax()){
            $params = $request->only(['scope','scope_name']);
            $bool = RuleModel::where('scope',$params['scope'])->update(['scope_name'=>$params['scope_name']]);
            if(!$bool){
                throw new RuleException([
                    'msg'=>'权限修改失败',
                    'errorCode'=>400
                ]);
            }
            return json(['code'=>201,'msg'=>'修改成功']);
        }
    }
}